import store from '../store';
import router from './router';
import {menus} from './menu';
import NProgress from 'nprogress';
import 'nprogress/nprogress.css';

router.beforeEach((to, from, next) =>
{
  NProgress.start();
  let token = store.getters.token;
  
  //没有token，并且不是登录页面，跳转到登录页
  if(!token && to.name !== 'login')
  {
     next({name:'login'});
  }
  else
  {
    store.dispatch('GenerateMenus', menus).then(() =>
    {
      next();
    });
  }
  
});

router.afterEach(() =>
{
  NProgress.done();
});

export default router;
